function AnalyseNature(n1,nStart)

% n1=1007;
% nStart=15000;
nSize=1000;
nSize2=200;
ValueFolder='/sps/isc/rneveu/EtudeIRM/Nature/';

if n1<10
    ValueTemp=['000' num2str(n1)];
else
    if n1<100
        ValueTemp=['00' num2str(n1)];
    else
        if n1<1000
            ValueTemp=['0' num2str(n1)];
        else
            ValueTemp=num2str(n1);
        end
    end
end
ValueFile=dir([ValueFolder 'pubmed/baseline/pubmed21n' ValueTemp '.xml']);
ValueFileTemp=ValueTemp;
if size(ValueFile,1)==0
    gunzip([ValueFolder 'pubmed/baseline/pubmed21n' ValueTemp '.xml.gz']);
end



% [VecJournal,VecJournalTemp]=xlsread('C:\Users\Remy Neveu\Desktop\Etude IRM\Analyse\pubmed\DonneesNature.xlsx');
% [VecEditors1,VecEditors1Temp]=xlsread('C:\Users\Remy Neveu\Desktop\Etude IRM\Article Region of interest\Etude Nature.xlsx',3);
load([ValueFolder 'DonneesNature.mat']);
load([ValueFolder 'EtudeNature.mat']);
VecEditors1Temp(1,:)=[];
for n2=1:size(VecEditors1Temp,1)
    VecEditors1TempCleaned(n2,1)={double(VecEditors1Temp{n2,1})};
    VecEditors1TempCleaned(n2,2)={double(VecEditors1Temp{n2,2})};
end
ValueSize=size(VecJournalTemp,1);
for n2=1:ValueSize
    eval(sprintf('VecResultJournal%d=cell(nSize,11);',n2));
    eval(sprintf('VecResult2Journal%d=cell(nSize,11);',n2));
    eval(sprintf('nJournal%d=0;',n2));
    eval(sprintf('n2Journal%d=0;',n2));
end
VecValueJournal=zeros(1,ValueSize);
VecValueJournal2=zeros(1,ValueSize);
for n2=1:size(VecEditors1Temp,1)
    eval(sprintf('VecResultEditors%d=cell(nSize2,14);',n2));
    eval(sprintf('nEditor%d=0;',n2));
end
VecValueEditor=zeros(1,size(VecEditors1Temp,1));
VecValueEditor2=zeros(1,size(VecEditors1Temp,1));
if n1<10
    ValueTemp=['000' num2str(n1)];
else
    if n1<100
        ValueTemp=['00' num2str(n1)];
    else
        if n1<1000
            ValueTemp=['0' num2str(n1)];
        else
            ValueTemp=num2str(n1);
        end
    end
end
ValueFile=fopen([ValueFolder 'pubmed/baseline/pubmed21n' ValueTemp '.xml']);
VecValue=fread(ValueFile);
n2=1;
if nStart==1
    nStart=1;
    nStop=7500;
else
    if nStart==2
        nStart=7500;
        nStop=15000;
    else
        if nStart==3
            nStart=15000;
            nStop=22500;
        else
            nStart=22500;
            nStop=100000;
        end
    end
end
n4=1;
ValueTemp2=size(VecValue,1)-19;
fclose(ValueFile);
ValueTemp4=clock;
disp([num2str(n2-1) ' elements processed at ' num2str(ValueTemp4(1,4)) ':' num2str(ValueTemp4(1,5)) ':' num2str(ValueTemp4(1,6))]);
n21=0;
n21Temp=0;
ValueDate2='';
VecStart=NaN(30000,1);
TestArticle=0;
%     VecTest={'<DateRevised>' '<Journal>' '<ArticleTitle>' '<AuthorList Complete' '<KeywordList Owner' '<PublicationType UI='};
%     VecTest={'<PubDate>' '</JournalIssue>' '<ArticleTitle>' '<AuthorList Complete' '<KeywordList Owner' '<PublicationType UI='};
VecTest={'<Journal>' '<ArticleTitle>' '<Abstract' '<OtherAbstract' '<AuthorList Complete' '<KeywordList Owner' '<PublicationType UI='};
%     VecValueTemp=[12 8 13 19 17 19];
%     VecValueTemp=[8 14 13 19 17 19];
VecValueTemp=[8 13 8 13 19 17 19];
VecA=192:1:198;
VecA=[VecA 65];
Veca=224:1:230;
Veca=[Veca 97];
VecC=[199 67];
Vecc=[231 99];
VecE=200:203;
VecE=[VecE 69];
Vece=232:1:235;
Vece=[Vece 101];
VecI=204:207;
VecI=[VecI 73];
Veci=236:1:239;
Veci=[Veci 105];
Vecn=[241 110];
VecO=210:214;
VecO=[VecO 216 79];
Veco=242:1:246;
Veco=[Veco 248 111];
VecU=217:1:220;
VecU=[VecU 85];
Vecu=249:1:252;
Vecu=[Vecu 117];
VecY=[221 89];
Vecy=[253 121];
Vecs=[223 115];
VecSpecialCharacters=[{VecA} {Veca} {VecC} {Vecc} {VecE} {Vece} {VecI} {Veci} {Vecn} {VecO} {Veco} {VecU} {Vecu} {VecY} {Vecy} {Vecs}];
n22=0;
ValueJournal2=-1;
ValueDate1='';
ValueJournal='';
ValueAuthors='';
ValueStatus='';
ValueEditor=[];
ValueKeywords='';
ValueArticle='';
ValueTitle='';
ValueAbstract=[];
ValueAbstract2=[];
VecResults=NaN(30000,14);
VecResults2=NaN(30000,9);
%     VecResultsJournal=NaN(30000,1);
n2Date1=NaN;
n2Date2=NaN;
n2Journal1Temp=NaN;
n2Journal2Temp=NaN;
n2Title1=NaN;
n2Title2=NaN;
n2Authors1=NaN;
n2Authors2=NaN;
n2Keywords1=NaN;
n2Keywords2=NaN;
n2ArticleType1=NaN;
n2ArticleType2=NaN;
n2Abstract=NaN;
n2Abstract2=NaN;
nAuthors=0;
nKeywords=0;
if nStart>1
    while n2<=ValueTemp2&&n21<nStart
        VecValueTemp2=VecValue(n2:n2+14,1);
        if strcmp(char(VecValue(n2:n2+15,1)'),'</PubmedArticle>')==1
            n21=n21+1;
        end
        n2=n2+1;
    end
end
n21Temp2=n21;
n6=1;
VecResults4=NaN(2000,10);
ValueTemp4=clock;
disp(['Start of the processing at ' num2str(ValueTemp4(1,4)) ':' num2str(ValueTemp4(1,5)) ':' num2str(ValueTemp4(1,6))]);
while n2<=ValueTemp2&&n21<=nStop
    VecValueTemp2=VecValue(n2:n2+14,1);
%         if strcmp(char(VecValueTemp2'),'<DateRevised>')==1
    if strcmp(char(VecValue(n2:n2+14,1)'),'<PubmedArticle>')==1
        n21Temp=n21Temp+1;
        TestArticle=1;
    else
        if strcmp(char(VecValue(n2:n2+15,1)'),'</PubmedArticle>')==1
            TestArticle=-1;
        end
    end
    if TestArticle==1
        TestTemp=0;
        n3=1;
        while TestTemp==0&&n3<=7
            if strcmp(char(VecValue(n2:n2+VecValueTemp(1,n3),1)'),VecTest{1,n3})==1
                TestTemp=n3;
            else
                n3=n3+1;
            end
        end
        if TestTemp==1&&size(ValueDate1,2)==0
            n2Date1=n2;
            [n2,ValueDate1]=getDate(VecValue,n2);
            n2Date2=n2;
            n2Journal1Temp=n2;
            [n2,ValueJournal,ValueJournal2]=getJournal(VecValue,n2,VecJournalTemp);
            n2Journal2Temp=n2;
%                 n2=n2+VecValueTemp(1,TestTemp);
        else
%                 if TestTemp==2&&size(ValueJournal,2)==0
%                     n2Journal1=n2;
%                     [n2,ValueJournal,ValueJournal2]=getJournal(VecValue,n2,VecJournalTemp);
%                     n2Journal2=n2;
%                 else
                if TestTemp==2&&size(ValueTitle,2)==0
                    n2Title1=n2;
                    [n2,ValueTitle]=getArticleTitle(VecValue,n2);
                    n2Title2=n2;
%                         n2=n2+VecValueTemp(1,TestTemp);
                else
                    if TestTemp==3&&size(ValueAbstract,2)==0
                        [n2,ValueAbstract]=getAbstractSize(VecValue,n2);
                        n2Abstract=n2;
%                             n2=n2+VecValueTemp(1,TestTemp);
                    else
                        if TestTemp==4&&size(ValueAbstract2,2)==0
                            [n2,ValueAbstract2]=getAbstractSize2(VecValue,n2);
                            n2Abstract2=n2;
%                                 n2=n2+VecValueTemp(1,TestTemp);
                        else
                            if TestTemp==5&&size(ValueAuthors,2)==0
                                [n2,ValueStatus]=getStatus(VecValue,n2);
                                n2Authors1=n2;
%                                     [n2,ValueAuthors,ValueEditor,nAuthors]=getAuthors(VecValue,n2,VecEditors1Temp,VecEditors1TempCleaned);
                                [n2,ValueAuthors,ValueEditor,nAuthors]=getAuthors(VecValue,n2,VecEditors1TempCleaned,VecSpecialCharacters);
                                n2Authors2=n2;
%                                     n2=n2+VecValueTemp(1,TestTemp);
                            else
                                if TestTemp==6&&size(ValueKeywords,2)==0
                                    n2Keywords1=n2;
                                    [n2,ValueKeywords,nKeywords]=getKeyword(VecValue,n2);
                                    n2Keywords2=n2;
%                                         n2=n2+VecValueTemp(1,TestTemp);
                                else
                                    if TestTemp==7&&size(ValueArticle,2)==0
                                        n2ArticleType1=n2;
                                        [n2,ValueArticle,ValueArticleTemp]=getArticleType(VecValue,n2);
                                        n2ArticleType2=n2;
%                                             n2=n2+VecValueTemp(1,TestTemp);
                                    end
                                end
                            end
                        end
                    end
                end
%                 end
        end
    else
        if TestArticle==-1&&size(ValueJournal,2)>=1
            TestArticle=0;
            n21=n21+1;
%             ValueTitle
%             ValueDate1
%             ValueJournal
%             ValueAbstract
%             ValueAbstract2
%             nAuthors
%             ValueArticle
%             ValueKeywords
%                 VecResultsJournal(n21-nStart,1)=size(ValueJournal,2);
            VecResults(n21,:)=[n2Authors1 n2Authors2 n2Journal1Temp n2Journal2Temp n2Date1 n2Date2  n2Title1 n2Title2 n2Keywords1 n2Keywords2 n2ArticleType1 n2ArticleType2 n2Abstract n2Abstract2];
            VecResults2(n21,:)=[size(ValueAuthors,2) size(ValueStatus,2) size(ValueJournal,2) size(ValueDate1,2) size(ValueTitle,2) size(ValueKeywords,2) size(ValueArticle,2) size(ValueAbstract,2) size(ValueAbstract2,2)];
            if ValueJournal2>-1||size(ValueEditor,2)>=1
                if size(ValueAuthors,2)>=1
                    if ValueJournal2>-1&&ValueArticleTemp==1
                        eval(sprintf('nJournal%d=nJournal%d+1;',ValueJournal2,ValueJournal2));
                        eval(sprintf('VecResultJournal%d(nJournal%d,:)=[{ValueAuthors} {nAuthors} {ValueStatus} {ValueJournal} {ValueDate1} {ValueTitle} {ValueKeywords} {nKeywords} {ValueArticle} {ValueAbstract} {ValueAbstract2}];',ValueJournal2,ValueJournal2));
                        VecValueJournal(1,ValueJournal2)=VecValueJournal(1,ValueJournal2)+1;
                    end
                    if ValueJournal2>-1
                        eval(sprintf('n2Journal%d=n2Journal%d+1;',ValueJournal2,ValueJournal2));
                        eval(sprintf('VecResult2Journal%d(n2Journal%d,:)=[{ValueAuthors} {nAuthors} {ValueStatus} {ValueJournal} {ValueDate1} {ValueTitle} {ValueKeywords} {nKeywords} {ValueArticle} {ValueAbstract} {ValueAbstract2}];',ValueJournal2,ValueJournal2));
                        VecValueJournal2(1,ValueJournal2)=VecValueJournal2(1,ValueJournal2)+1;
    %                     if ValueJournal2==32&&size(ValueAuthors,2)==0
    %                         ValueResults44=VecValue(n2Journal2Temp-200:n2Journal2Temp+200,1)';
    %                         disp(char(ValueResults44))
    %                         pause()
    %                         VecResults4(n6,:)=[n6 size(ValueAuthors,2) size(ValueStatus,2) size(ValueJournal,2) size(ValueDate1,2) size(ValueTitle,2) size(ValueArticle,2) size(ValueAbstract,2) size(ValueAbstract2,2) n2Journal2Temp];
    %                         n6=n6+1;
    %                     end
                    end
                    if size(ValueEditor,2)>=1
                        for n3=1:size(ValueEditor,2)
                            eval(sprintf('nEditor%d=nEditor%d+1;',ValueEditor(1,n3),ValueEditor(1,n3)));
                            eval(sprintf('VecResultEditors%d(nEditor%d,:)=[{ValueAuthors} {nAuthors} {ValueStatus} {ValueJournal} {ValueDate1} {ValueTitle} {ValueKeywords} {nKeywords} {ValueArticle} {ValueEditor(1,n3)} {ValueEditor} {size(ValueEditor,2)} {ValueAbstract} {ValueAbstract2}];',ValueEditor(1,n3),ValueEditor(1,n3)));
                            VecValueEditor(1,ValueEditor(1,n3))=VecValueEditor(1,ValueEditor(1,n3))+1;
                        end
                        if size(ValueEditor,2)>1
                            for n3=1:size(ValueEditor,2)
                                VecValueEditor2(1,ValueEditor(1,n3))=VecValueEditor2(1,ValueEditor(1,n3))+1;
                            end
                        end
                    end
                end
            end
            ValueJournal2=-1;
            ValueDate1='';
            ValueJournal='';
            ValueAuthors='';
            ValueStatus='';
            ValueEditor=[];
            ValueKeywords='';
            ValueArticle='';
            ValueTitle='';
            ValueAbstract=[];
            ValueAbstract2=[];
            n2Date1=NaN;
            n2Date2=NaN;
            n2Journal1Temp=NaN;
            n2Journal2Temp=NaN;
            n2Title1=NaN;
            n2Title2=NaN;
            n2Authors1=NaN;
            n2Authors2=NaN;
            n2Keywords1=NaN;
            n2Keywords2=NaN;
            n2ArticleType1=NaN;
            n2ArticleType2=NaN;
            n2Abstract=NaN;
            n2Abstract2=NaN;
            nAuthors=0;
            nKeywords=0;
        end
    end
    n2=n2+1;
end
ValueTemp4=clock;
disp([num2str(n2) ' elements processed at ' num2str(ValueTemp4(1,4)) ':' num2str(ValueTemp4(1,5)) ':' num2str(ValueTemp4(1,6))]);
eval(sprintf('ValueFile=dir([ValueFolder ''Results/AllResultsFile%d.mat'']);',n1));
if size(ValueFile,1)==1
    VecValueJournalTemp=VecValueJournal;
    VecValueJournal2Temp=VecValueJournal2;
    VecValueEditorTemp=VecValueEditor;
    VecValueEditor2Temp=VecValueEditor2;
    load([ValueFolder 'Results/' ValueFile.name]);
    VecValueJournal=VecValueJournal+VecValueJournalTemp;
    VecValueJournal2=VecValueJournal2+VecValueJournal2Temp;
    VecValueEditor=VecValueEditor+VecValueEditorTemp;
    VecValueEditor2=VecValueEditor2+VecValueEditor2Temp;
    ValueFileTemp3=ValueFile.name;
else
    eval(sprintf('ValueFileTemp3=''AllResultsFile%d.mat'';',n1));
end
for n2=1:ValueSize
    eval(sprintf('VecResultTemp=VecResultJournal%d;',n2));
    TestTemp=0;
    n3=1;
    while TestTemp==0&&n3<=nSize
        if size(VecResultTemp{n3,4},2)>0
            n3=n3+1;
        else
            TestTemp=1;
        end
    end
    if n3>1
        eval(sprintf('VecResultJournal%dTemp=VecResultTemp(1:n3-1,:);',n2));
    else
        eval(sprintf('VecResultJournal%dTemp=[];',n2));
    end
    eval(sprintf('VecResultTemp=VecResult2Journal%d;',n2));
    TestTemp=0;
    n3=1;
    while TestTemp==0&&n3<=nSize
        if size(VecResultTemp{n3,4},2)>0
            n3=n3+1;
        else
            TestTemp=1;
        end
    end
    if n3>1
        eval(sprintf('VecResult2Journal%dTemp=VecResultTemp(1:n3-1,:);',n2));
    else
        eval(sprintf('VecResult2Journal%dTemp=[];',n2));
    end
end
for n2=1:size(VecEditors1Temp,1)
    eval(sprintf('VecResultTemp=VecResultEditors%d;',n2));
    TestTemp=0;
    n3=1;
    while TestTemp==0&&n3<=nSize2
        if size(VecResultTemp{n3,1},2)>0
            n3=n3+1;
        else
            TestTemp=1;
        end
    end
    if n3>1
        eval(sprintf('VecResultEditors%dTemp=VecResultTemp(1:n3-1,:);',n2));
    else
        eval(sprintf('VecResultEditors%dTemp=[];',n2));
    end
end
ValueResultsTemp=[nStart nStop n21Temp2 n21 n21Temp n2 ValueTemp2];
VecResultsTemp=VecResults;
VecResults2Temp=VecResults2;
ValueTemp=['save([ValueFolder ''Results/ResultsFile' num2str(n1) '.mat''],'];
for n2=1:ValueSize
%         if n2<ValueSize
        ValueTemp=[ValueTemp '''VecResultJournal' num2str(n2) ''',' '''VecResult2Journal' num2str(n2) ''','];
%         else
%             ValueTemp=[ValueTemp 'VecResultJournal' num2str(n2) ''',' 'VecResult2Journal' num2str(n2) ''');'];
%         end
end
for n2=1:size(VecEditors1Temp,1)
    if n2<size(VecEditors1Temp,1)
        ValueTemp=[ValueTemp '''VecResultEditors' num2str(n2) ''','];
    else
        ValueTemp=[ValueTemp '''VecResultEditors' num2str(n2) ''');'];
    end
end
eval(sprintf('ValueFile=dir([ValueFolder ''Results/ResultsFile%d.mat'']);',n1));
eval(sprintf('ValueFile2=dir([ValueFolder ''Results/OutputResultsFile%d.mat'']);',n1));
if size(ValueFile,1)==1
    load([ValueFolder 'Results/' ValueFile.name]);
    for n2=1:ValueSize
        eval(sprintf('VecResultJournal%d=[VecResultJournal%d;VecResultJournal%dTemp];',n2,n2,n2));
        eval(sprintf('VecResult2Journal%d=[VecResult2Journal%d;VecResult2Journal%dTemp];',n2,n2,n2));
    end
    for n2=1:size(VecEditors1Temp,1)
        eval(sprintf('VecResultEditors%d=[VecResultEditors%d;VecResultEditors%dTemp];',n2,n2,n2));
    end
    load([ValueFolder 'Results/' ValueFile2.name]);
    ValueResults=[ValueResults;ValueResultsTemp];
    for n2=1:size(VecResultsTemp,1)
        if isnan(VecResultsTemp(n2,1))==0&&isnan(VecResultsTemp(n2,2))==0&&isnan(VecResultsTemp(n2,3))==0&&isnan(VecResultsTemp(n2,4))==0
            for n3=1:size(VecResultsTemp,2)
                VecResults(n2,n3)=VecResultsTemp(n2,n3);
            end
        end
    end
    for n2=1:size(VecResults2Temp,1)
        if isnan(VecResults2Temp(n2,1))==0&&isnan(VecResults2Temp(n2,2))==0&&isnan(VecResults2Temp(n2,3))==0&&isnan(VecResults2Temp(n2,4))==0
            for n3=1:size(VecResults2Temp,2)
                VecResults2(n2,n3)=VecResults2Temp(n2,n3);
            end
        end
    end
else
    for n2=1:ValueSize
        eval(sprintf('VecResultJournal%d=VecResultJournal%dTemp;',n2,n2));
        eval(sprintf('VecResult2Journal%d=VecResult2Journal%dTemp;',n2,n2));
    end
    for n2=1:size(VecEditors1Temp,1)
        eval(sprintf('VecResultEditors%d=VecResultEditors%dTemp;',n2,n2));
    end
    ValueResults=ValueResultsTemp;
    VecResults=VecResultsTemp;
    VecResults2=VecResults2Temp;
end
save([ValueFolder 'Results/' ValueFileTemp3],'VecValueJournal','VecValueJournal2','VecValueEditor','VecValueEditor2');
eval(ValueTemp);
VecValueJournal2Temp=VecValueJournal2;
ValueTemp=['save([ValueFolder ''Results/OutputResultsFile' num2str(n1) '.mat''],''ValueResults'',''VecResults'',''VecResults2'',''VecValueJournal2Temp'');'];
eval(ValueTemp);
if nStop>30000
    delete([ValueFolder 'pubmed/baseline/pubmed21n' ValueFileTemp '.xml']);
end
